// pages/wallet/wallet.js
var util = require('../../utils/util.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    withdraw:false,
    finacneData:[],
    withdrawPrice:0
  },
  start_detail(){
    app.navTo('../detail/detail')
  },
  //提现记录
  withdrawrec(){
    app.navTo('../withdrawrec/withdrawrec')
  },
  //充值
  recharge(){
    app.navTo('../recharge/recharge')
  },
  //提现
  withdraw() {
    this.setData({
      withdraw: true
    })
  },
  withdrawPrice:function(e){
    var price = e.detail.value;
    this.setData({
      withdrawPrice:price
    })
 
  },
  //提现确认
  withdrawsure(){
    var that = this;
    let can_get_money = this.data.finacneData.available_balance;
    console.log(can_get_money);
    can_get_money = parseFloat(can_get_money);
    let withdrawPrice = parseFloat(this.data.withdrawPrice)
    if (withdrawPrice > can_get_money) {
      wx.showToast({
        title: "余额不足",
        icon: 'none'
      });
      return
    }
    this.setData({
      withdraw:false
    })
    wx.navigateTo({
      url: "tixian_page/tixian_page?money=" + withdrawPrice
    })





    return;
    util.commonRequest('applyWithdrawal', 'post', { money: this.data.withdrawPrice}, function (res) {
      if (res.data.code == 200) {
        wx.showToast({
          title: res.data.msg
        })
      } else {
        wx.showToast({
          icon: 'loading',
          title: res.data.msg,
        })
      }
    });
    this.setData({
      withdraw: false
    })
  },
  //余额提现取消
  cancel(){
    this.setData({
      withdraw:false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initUserFinance();
  },
  initUserFinance:function(){
    var that = this;
    util.commonRequest('userFinance', 'post', {}, function (res) {
      if (res.data.code == 200) {
       that.setData({
         finacneData:res.data.data
       })
      } else {
        wx.showToast({
          icon: 'loading',
          title: res.data.msg,
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  applyWithdral:function(){
    var that = this;
    util.commonRequest('bannerList', 'post', {}, function (res) {
      if (res.data.code == 200) {
        that.setData({
          movies: res.data.data
        })
      } else {
        wx.showToast({
          icon: 'loading',
          title: res.data.msg,
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})